package com.tanhua.manage.controller;

import com.tanhua.manage.service.HomeYanService;
import com.tanhua.manage.vo.SummaryVo;
import com.tanhua.manage.vo.UsersVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * yan
 */
@RestController
@RequestMapping("dashboard")
@Slf4j
public class HomeYanController {

    @Autowired
    private HomeYanService homeYanService;

    /**
     * 查询概要统计信息
     *
     * @return
     */
    @GetMapping("summary")
    public ResponseEntity<SummaryVo> querySummary() {

        try {
            SummaryVo summaryVo = this.homeYanService.querySummary();
            return ResponseEntity.ok(summaryVo);
        } catch (Exception e) {
            log.error("查询不到数据", e);
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    /**
     * 查询各种用户数据
     * 新增用户
     * 活跃用户
     * 次日留存用户
     *
     * @return
     */
    @GetMapping("users")
    public ResponseEntity<UsersVo> queryUsers(@RequestParam Long sd,
                                              @RequestParam Long ed,
                                              @RequestParam Long type
    ) {
        try {
            UsersVo usersVo = this.homeYanService.queryUsers(sd, ed, type);
            return ResponseEntity.ok(usersVo);
        } catch (Exception e) {
            log.error("查询不到数据", e);
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

}
